namespace OneBlog.DataAccessLayer.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class AddAllBlog : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.BlogComment",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Content = c.String(maxLength: 400),
                        UserId = c.Int(nullable: false),
                        BlogInfoId = c.Int(nullable: false),
                        CreateTime = c.DateTime(),
                        DeleteTime = c.DateTime(),
                        IsDelete = c.Boolean(nullable: false),
                        IsActive = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.BlogUser", t => t.UserId)
                .ForeignKey("dbo.BlogInfo", t => t.BlogInfoId)
                .Index(t => t.UserId)
                .Index(t => t.BlogInfoId);
            
            CreateTable(
                "dbo.BlogInfo",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Content = c.String(),
                        Title = c.String(nullable: false, maxLength: 200),
                        Url = c.String(maxLength: 200),
                        IsForwarding = c.Boolean(nullable: false),
                        ReadNum = c.Int(),
                        ForUrl = c.String(maxLength: 200),
                        IsShowHome = c.Boolean(),
                        IsShowMyHome = c.Boolean(nullable: false),
                        UserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(),
                        DeleteTime = c.DateTime(),
                        IsDelete = c.Boolean(nullable: false),
                        IsActive = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.BlogUser", t => t.UserId)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.BlogType",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 100),
                        Description = c.String(maxLength: 400),
                        Type = c.Int(nullable: false),
                        UserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(),
                        DeleteTime = c.DateTime(),
                        IsDelete = c.Boolean(nullable: false),
                        IsActive = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.BlogUser", t => t.UserId)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.BlogUser",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        UserName = c.String(nullable: false, maxLength: 40),
                        Password = c.String(nullable: false, maxLength: 40),
                        NickName = c.String(nullable: false, maxLength: 20),
                        Email = c.String(nullable: false, maxLength: 20),
                        Photo = c.String(maxLength: 100),
                        CreateTime = c.DateTime(),
                        DeleteTime = c.DateTime(),
                        IsDelete = c.Boolean(nullable: false),
                        IsActive = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.BlogSubComment",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Content = c.String(maxLength: 400),
                        CreateUserId = c.Int(nullable: false),
                        RepleyUserId = c.Int(nullable: false),
                        RootCommentId = c.Int(nullable: false),
                        CreateTime = c.DateTime(),
                        DeleteTime = c.DateTime(),
                        IsDelete = c.Boolean(nullable: false),
                        IsActive = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.BlogUser", t => t.CreateUserId)
                .ForeignKey("dbo.BlogUser", t => t.RepleyUserId)
                .ForeignKey("dbo.BlogComment", t => t.RootCommentId)
                .Index(t => t.CreateUserId)
                .Index(t => t.RepleyUserId)
                .Index(t => t.RootCommentId);
            
            CreateTable(
                "dbo.BlogInfoBlogTypes",
                c => new
                    {
                        BlogInfo_Id = c.Int(nullable: false),
                        BlogType_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.BlogInfo_Id, t.BlogType_Id })
                .ForeignKey("dbo.BlogInfo", t => t.BlogInfo_Id)
                .ForeignKey("dbo.BlogType", t => t.BlogType_Id)
                .Index(t => t.BlogInfo_Id)
                .Index(t => t.BlogType_Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.BlogSubComment", "RootCommentId", "dbo.BlogComment");
            DropForeignKey("dbo.BlogSubComment", "RepleyUserId", "dbo.BlogUser");
            DropForeignKey("dbo.BlogSubComment", "CreateUserId", "dbo.BlogUser");
            DropForeignKey("dbo.BlogComment", "BlogInfoId", "dbo.BlogInfo");
            DropForeignKey("dbo.BlogInfoBlogTypes", "BlogType_Id", "dbo.BlogType");
            DropForeignKey("dbo.BlogInfoBlogTypes", "BlogInfo_Id", "dbo.BlogInfo");
            DropForeignKey("dbo.BlogType", "UserId", "dbo.BlogUser");
            DropForeignKey("dbo.BlogInfo", "UserId", "dbo.BlogUser");
            DropForeignKey("dbo.BlogComment", "UserId", "dbo.BlogUser");
            DropIndex("dbo.BlogInfoBlogTypes", new[] { "BlogType_Id" });
            DropIndex("dbo.BlogInfoBlogTypes", new[] { "BlogInfo_Id" });
            DropIndex("dbo.BlogSubComment", new[] { "RootCommentId" });
            DropIndex("dbo.BlogSubComment", new[] { "RepleyUserId" });
            DropIndex("dbo.BlogSubComment", new[] { "CreateUserId" });
            DropIndex("dbo.BlogType", new[] { "UserId" });
            DropIndex("dbo.BlogInfo", new[] { "UserId" });
            DropIndex("dbo.BlogComment", new[] { "BlogInfoId" });
            DropIndex("dbo.BlogComment", new[] { "UserId" });
            DropTable("dbo.BlogInfoBlogTypes");
            DropTable("dbo.BlogSubComment");
            DropTable("dbo.BlogUser");
            DropTable("dbo.BlogType");
            DropTable("dbo.BlogInfo");
            DropTable("dbo.BlogComment");
        }
    }
}
